package main

import (
	"fly_export/cron"
	"fly_export/global"
	"fly_export/router"
	"fmt"

	"github.com/labstack/echo"
	"github.com/prometheus/client_golang/prometheus"
)

func main() {
	global.GVA_VP = global.Viper()
	// databases.NewMysql()
	Alerload()

	e := echo.New()
	cron.RunCron()
	router.Register(e)
	e.Logger.Fatal(e.Start(fmt.Sprint(":", global.GVA_CONFIG.Server.ServerPort)))
}

func Alerload() {
	global.GVA_ALERTLOAD = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "alert",
			Help: "alert result",
		},
		[]string{"url", "name"},
	)
	global.GVA_ALERTLOAD2 = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "alerttime",
			Help: "times ",
		},
		[]string{"url", "name"},
	)
	prometheus.MustRegister(global.GVA_ALERTLOAD, global.GVA_ALERTLOAD2)

	// var alerts []databases.Alert
	// global.GVA_MYSQL.Find(&alerts)
	// for _, v := range global.GVA_CONFIG.Alerts {
	// 	log.Println("初始化程序" + v.Url)
	// 	v.Run()
	// }
	// for _, vt := range global.GVA_CONFIG.Times {
	// 	log.Println("初始化程序" + vt.Url)
	// 	vt.Run()
	// }\
	global.Run(global.GVA_CONFIG.Alerts)
	global.Run(global.GVA_CONFIG.Times)
}
